package com.alibaba.csp.sentinel.dashboard.auth.jwt;

import com.alibaba.csp.sentinel.dashboard.auth.AuthService;

import java.io.Serializable;
import java.util.Set;

/**
 * 用途描述：用户信息
 *
 * @author YangLong
 * @version V1.0
 * @since 2024/2/26
 */
public class JwtUser implements AuthService.AuthUser, Serializable {
    private String tokenId;
    private String id;

    private String mobile;

    private String avatar;

    private String loginName;

    private String username;

    private Set<String> roles;

    private Set<String> perms;

    public String getTokenId() {
        return tokenId;
    }

    public void setTokenId(String tokenId) {
        this.tokenId = tokenId;
    }

    @Override
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @Override
    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public String getNickName() {
        return username;
    }

    public Set<String> getRoles() {
        return roles;
    }

    public void setRoles(Set<String> roles) {
        this.roles = roles;
    }

    public Set<String> getPerms() {
        return perms;
    }

    public void setPerms(Set<String> perms) {
        this.perms = perms;
    }

    @Override
    public boolean authTarget(String target, AuthService.PrivilegeType privilegeType) {
        //这里要使用请求中参数target和方法注解上的权限进行对比，看是否一致，另外再根据perms查看是否有权限
        return true;
    }

    @Override
    public boolean isSuperUser() {
        //可以根据roles中是否有管理角色返回
        return false;
    }
}
